package com.jsyxdl.utils;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.basic.log.LogEventEnum;
import com.hustcad.plm.basic.util.TyCommonExtUtil;
import com.hustcad.plm.basic.util.TyplmEntityBaseUtil;
import com.hustcad.plm.pdm.audit.model.dto.TyplmAuditChangeLCLogDTO;
import com.hustcad.plm.pdm.audit.util.TyplmAuditLogUtil;
import com.hustcad.plm.pdm.common.model.dto.EntityMessageDTO;
import com.hustcad.plm.pdm.common.service.entity.TyplmEntityBaseService;
import com.hustcad.plm.pdm.common.util.CommonUtil;
import com.hustcad.plm.pdm.common.util.TyplmPermissionsUtil;
import com.hustcad.plm.pdm.enumeration.service.TyplmLocalePropertyValueService;
import com.hustcad.plm.pdm.folder.model.constant.FolderQueryConstant;
import com.hustcad.plm.pdm.lifestage.mapper.TyplmPhaseSuccessionMapper;
import com.hustcad.plm.pdm.lifestage.model.constant.LifeStageErrorCodeEnum;
import com.hustcad.plm.pdm.lifestage.model.dto.*;
import com.hustcad.plm.pdm.lifestage.model.vo.LifeCycleStageVO;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifeCycleHistoryService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifecycleStageService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifecycleStageTemplateService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifecycleTemplateService;
import com.hustcad.plm.pdm.user.service.TyplmTeamForStageService;
import com.ty.basic.common.ITyLifeCycleManaged;
import com.ty.basic.common.ITyLockable;
import com.ty.basic.common.ITyUpdator;
import com.ty.basic.entity.CTyEntityBaseDO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.org.UserDO;
import com.ty.basic.enums.StatusActionEnum;
import com.ty.basic.handler.exceptionhandler.exception.ResponseCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.TyException;
import com.ty.basic.session.TyAccountContext;
import com.ty.basic.util.TyMessageUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.math.BigInteger;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class LifeCycleOperatorListenerUtils {

    /**
     * 前端接口调用的方法
     *
     * @param entityLifeCycleList
     */
    public List<EntityMessageDTO> batchUpdateEntityLifecycle(List<EntityLifeCycleDTO> entityLifeCycleList,
                                                             Boolean excludeException, boolean ignoreNotExistState,
                                                             boolean ignoreCheckAccess) {
        TyplmLocalePropertyValueService typlmLocalePropertyValueService = SpringUtil.getBean(
                TyplmLocalePropertyValueService.class);
        if (CollectionUtils.isEmpty(entityLifeCycleList)) {
            return new ArrayList();
        } else {
            Map<IdentifierEntity, String> entityNewStateMap = new HashMap();
            Iterator var6 = entityLifeCycleList.iterator();

            while (var6.hasNext()) {
                EntityLifeCycleDTO entity = (EntityLifeCycleDTO) var6.next();
                TyplmEntityBaseUtil.checkParamNotNull(entity.getLifeCycleStageKey(), "LifeCycleStageKey");
                entityNewStateMap.put(new IdentifierEntity(entity.getOid(), entity.getOtype()),
                                      entity.getLifeCycleStageKey());
            }

            List<CTyEntityBaseDO> entityList = CommonUtil.getEntityListIgnoreNotExist(entityNewStateMap.keySet());
            List<TyTemplateAndStagesDTO> templateList = this.getTemplateAndStages(entityList);
            List<String> stageList = (List) entityLifeCycleList.stream().map(EntityLifeCycleDTO::getLifeCycleStageKey)
                    .distinct().collect(Collectors.toList());
            Map<String, String> localMap = typlmLocalePropertyValueService.queryLocaleValueByItem(new ArrayList(),
                                                                                                  "LifeCycleState",
                                                                                                  TyCommonExtUtil.getFrontLanguage());
            Iterator var10 = entityLifeCycleList.iterator();

            while (var10.hasNext()) {
                EntityLifeCycleDTO lifeCycleDTO = (EntityLifeCycleDTO) var10.next();
                CTyEntityBaseDO baseDO = (CTyEntityBaseDO) entityList.stream().filter((item) -> {
                    return item.getOid().equals(lifeCycleDTO.getOid());
                }).findAny().orElse(null);
                if (baseDO != null && baseDO instanceof ITyLifeCycleManaged) {
                    BigInteger lifecycletemplateoid = ((ITyLifeCycleManaged) baseDO).getLifecycletemplateoid();
                    String stagekey = ((ITyLifeCycleManaged) baseDO).getLifecyclestagekey();
                    List<TyLifecycleStateDTO> stateDTOList = this.getTyLifecycleStateDTOS(templateList,
                                                                                          lifecycletemplateoid,
                                                                                          stagekey);
                    if (CollectionUtils.isEmpty(stateDTOList)) {
                        throw LifeStageErrorCodeEnum.TEMPLATE_INCONSISTENT_CANNOT_OPERATE.getException(
                                new Object[]{localMap.get(lifeCycleDTO.getLifeCycleStageKey())});
                    }

                    boolean isMatch = stateDTOList.stream().anyMatch((item) -> {
                        return item.getCode().equals(lifeCycleDTO.getLifeCycleStageKey());
                    });
                    if (!isMatch) {
                        throw LifeStageErrorCodeEnum.LIFE_STAGE_CANNOT_BE_SET.getException(
                                new Object[]{localMap.get(lifeCycleDTO.getLifeCycleStageKey())});
                    }

                    TyplmAuditChangeLCLogDTO typlmAuditChangeLCLogDTO = new TyplmAuditChangeLCLogDTO();
                    typlmAuditChangeLCLogDTO.setNewLCKey(lifeCycleDTO.getLifeCycleStageKey());
                    typlmAuditChangeLCLogDTO.setOldLCKey(stagekey);
                    typlmAuditChangeLCLogDTO.setOid(lifeCycleDTO.getOid());
                    typlmAuditChangeLCLogDTO.setOtype(lifeCycleDTO.getOtype());
                    TyplmAuditLogUtil.info(typlmAuditChangeLCLogDTO, LogEventEnum.CHANGE_LC_STATE,
                                           String.format("生命周期状态 %s -> %s", localMap.get(stagekey),
                                                         localMap.get(lifeCycleDTO.getLifeCycleStageKey())));
                }
            }

            TyplmEntityBaseUtil.checkNotExistByIdentifier(entityNewStateMap.keySet(), entityList);
            return batchUpdateEntityLifecycle(entityLifeCycleList, entityList, entityNewStateMap, excludeException,
                                              ignoreNotExistState, ignoreCheckAccess);
        }
    }

    private List<TyTemplateAndStagesDTO> getTemplateAndStages(List<? extends CTyEntityBaseDO> entityList) {
        TyplmLifecycleStageTemplateService typlmLifecycleStageTemplateService = SpringUtil.getBean(
                TyplmLifecycleStageTemplateService.class);
        Stream var10000 = entityList.stream();
        ITyLifeCycleManaged.class.getClass();
        List<BigInteger> templateOidList = (List) var10000.filter(ITyLifeCycleManaged.class::isInstance).map((item) -> {
            return ((ITyLifeCycleManaged) item).getLifecycletemplateoid();
        }).distinct().collect(Collectors.toList());
        List<TyTemplateAndStagesDTO> templateList = typlmLifecycleStageTemplateService.selectTemplateAndStageByTemplateId(
                templateOidList);
        if (ObjectUtils.isEmpty(templateList)) {
            String[] templateArray = (String[]) templateOidList.stream().map((item) -> {
                return "ty.inteplm.lifecycle.CTyLifecycleTemplate:" + item;
            }).toArray((x$0) -> {
                return new String[x$0];
            });
            TyException.throwSingleTyExceptionArray(ResponseCodeEnum.BIZ_LIFECYCLETEMPLATE_NOT_FOUND, templateArray);
        }

        this.sortTemplateStageListbyTyTemplateAndStagesDTOList(templateList);
        return templateList;
    }

    private void sortTemplateStageListbyTyTemplateAndStagesDTOList(List<TyTemplateAndStagesDTO> templateList) {
        TyplmLifecycleStageService typlmLifecycleStageService = SpringUtil.getBean(TyplmLifecycleStageService.class);
        if (!CollectionUtils.isEmpty(templateList)) {
            templateList.forEach((item) -> {
                BigInteger templateoid = item.getTemplateoid();
                List<LifeCycleStageVO> lifeCycleStage = typlmLifecycleStageService.getLifeCycleStage(templateoid);
                List<TyLifeCycleStageTemplateDTO> stageList = item.getStageList();
                Map<BigInteger, TyLifeCycleStageTemplateDTO> toSortMap = (Map) stageList.stream().collect(
                        Collectors.toMap(CTyEntityBaseDO::getOid, Function.identity(), (v1, v2) -> {
                            return v2;
                        }));
                List<TyLifeCycleStageTemplateDTO> sortList = (List) lifeCycleStage.stream().map((data) -> {
                    return (TyLifeCycleStageTemplateDTO) toSortMap.get(data.getOid());
                }).collect(Collectors.toList());
                item.setStageList(sortList);
            });
        }
    }

    private List<TyLifecycleStateDTO> getTyLifecycleStateDTOS(List<TyTemplateAndStagesDTO> templateList,
                                                              BigInteger lifecycletemplateoid, String stagekey) {
        TyplmPhaseSuccessionMapper typlmPhaseSuccessionMapper = SpringUtil.getBean(TyplmPhaseSuccessionMapper.class);
        TyplmLocalePropertyValueService typlmLocalePropertyValueService = SpringUtil.getBean(
                TyplmLocalePropertyValueService.class);

        TyTemplateAndStagesDTO templateAndStagesDTO = (TyTemplateAndStagesDTO) templateList.stream().filter((item) -> {
            return item.getTemplateoid().equals(lifecycletemplateoid);
        }).findFirst().orElse(null);
        if (templateAndStagesDTO == null) {
            return Collections.emptyList();
        } else {
            List<TyLifeCycleStageTemplateDTO> stageList = templateAndStagesDTO.getStageList();
            TyLifeCycleStageTemplateDTO templateDTO = (TyLifeCycleStageTemplateDTO) stageList.stream().filter(
                    (item) -> {
                        return StringUtils.equals(item.getStagestate(), stagekey);
                    }).findFirst().orElse(null);
            if (templateDTO == null) {
                return Collections.emptyList();
            } else {
                List<EditStateChangeDTO> editStateChangeS = typlmPhaseSuccessionMapper.queryStageChangeList(
                        templateDTO.getOid());
                if (CollectionUtils.isEmpty(editStateChangeS)) {
                    return Collections.emptyList();
                } else {
                    List<BigInteger> oidList = (List) editStateChangeS.stream().filter((item) -> {
                        return StringUtils.equals(item.getLanguagekey(), "SET_STATE");
                    }).map(EditStateChangeDTO::getOid).collect(Collectors.toList());
                    List<TyLifeCycleStageTemplateDTO> setStageList = (List) stageList.stream().filter((item) -> {
                        return oidList.contains(item.getOid());
                    }).collect(Collectors.toList());
                    if (CollectionUtils.isEmpty(setStageList)) {
                        return Collections.emptyList();
                    } else {
                        Map<String, String> map = typlmLocalePropertyValueService.queryLocaleValueByItem(
                                (Collection) setStageList.stream().map(TyLifeCycleStageTemplateDTO::getStagestate)
                                        .collect(Collectors.toList()), "LifeCycleState",
                                TyCommonExtUtil.getFrontLanguage());
                        return (List) setStageList.stream().map((data) -> {
                            TyLifecycleStateDTO stateDTO = new TyLifecycleStateDTO();
                            stateDTO.setCode(data.getStagestate());
                            stateDTO.setName((String) map.get(data.getStagestate()));
                            return stateDTO;
                        }).collect(Collectors.toList());
                    }
                }
            }
        }
    }

    private List<EntityMessageDTO> batchUpdateEntityLifecycle(List<EntityLifeCycleDTO> entityLifeCycleList,
                                                              List<? extends CTyEntityBaseDO> entityList,
                                                              Map<IdentifierEntity, String> entityNewStateMap,
                                                              boolean excludeException, boolean ignoreNotExistState,
                                                              boolean ignoreCheckAccess) {
        TyplmPermissionsUtil typlmPermissionsUtil = SpringUtil.getBean(TyplmPermissionsUtil.class);

        if (!CollectionUtils.isEmpty(entityList) && !CollectionUtils.isEmpty(entityNewStateMap)) {
            List<EntityMessageDTO> messageDTOList = new ArrayList();
            this.checkIteratorStatus(entityList, messageDTOList);
            UserDO currentUser = CommonUtil.getUser();
            if (!ignoreCheckAccess) {
                List<String> statList = (List) entityList.parallelStream().map((entityx) -> {
                    return "设置状态";
                }).collect(Collectors.toList());
                List<EntityMessageDTO> messageDTOS = typlmPermissionsUtil.checkObjectPermissionAndGetExceptionMessage(
                        currentUser, entityList, statList);
                messageDTOList.addAll(messageDTOS);
            }

            Map<BigInteger, Map<String, TyLifeCycleStageTemplateDTO>> templateStagesMap = this.getTemplateStagesMap(
                    entityList);
            List<NewLifeCycleStateHistoryDTO> lifeCycleStateHistoryDTOS = new ArrayList();
            List<CTyEntityBaseDO> updateEntityList = new ArrayList();
            List<CTyEntityBaseDO> refreshTeamEntityList = new ArrayList();
            List<BigInteger> filterList = this.filterStateList(entityLifeCycleList);
            entityList = (List) entityList.stream().filter((entityx) -> {
                return filterList.contains(entityx.getOid());
            }).collect(Collectors.toList());
            Iterator var14 = entityList.iterator();

            while (var14.hasNext()) {
                CTyEntityBaseDO entity = (CTyEntityBaseDO) var14.next();
                String stateCode = (String) entityNewStateMap.get(
                        new IdentifierEntity(entity.getOid(), entity.getOtype()));
                if (!this.checkStateNotExist(entity, templateStagesMap, ignoreNotExistState, stateCode,
                                             messageDTOList)) {
                    TyLifeCycleStageTemplateDTO stageDTO = (TyLifeCycleStageTemplateDTO) ((Map) templateStagesMap.get(
                            ((ITyLifeCycleManaged) entity).getLifecycletemplateoid())).get(stateCode);
                    String lastState = ((ITyLifeCycleManaged) entity).getLifecyclestagekey();
                    if (!Objects.isNull(stageDTO)) {
                        ((ITyLifeCycleManaged) entity).setLifecyclestagekey(stateCode);
                        ((ITyLifeCycleManaged) entity).setLifecyclestageoid(stageDTO.getOid());
                        ((ITyLifeCycleManaged) entity).setLifecyclestageotype(stageDTO.getOtype());
                    }

                    if (entity instanceof ITyUpdator) {
                        ((ITyUpdator) entity).setUpdatoroid(currentUser.getOid());
                        ((ITyUpdator) entity).setUpdatorotype(currentUser.getOtype());
                    }

                    lifeCycleStateHistoryDTOS.add(this.newLifecycleHistory(lastState, stateCode, currentUser, entity));
                    updateEntityList.add(entity);
                    refreshTeamEntityList.add(entity);

                }
            }

            return this.filterUpdateList(messageDTOList, excludeException, updateEntityList, refreshTeamEntityList,
                                         lifeCycleStateHistoryDTOS);
        } else {
            return new ArrayList();
        }
    }

    private void checkIteratorStatus(List<? extends CTyEntityBaseDO> cTyEntityBaseDOS,
                                     List<EntityMessageDTO> entityMessageDTOS) {
        Iterator var3 = cTyEntityBaseDOS.iterator();

        while (var3.hasNext()) {
            CTyEntityBaseDO cTyEntityBaseDO = (CTyEntityBaseDO) var3.next();
            if (cTyEntityBaseDO instanceof ITyLockable && "c/o".equalsIgnoreCase(
                    ((ITyLockable) cTyEntityBaseDO).getLockstateinfo())) {
                String type = (String) FolderQueryConstant.QUERY_OTYPE_TO_TYPE_MAP.getOrDefault(
                        cTyEntityBaseDO.getOtype(), cTyEntityBaseDO.getOtype());
                String displayName = CommonUtil.getEntityDisplayName(cTyEntityBaseDO);
                EntityMessageDTO entityMessageDTO = new EntityMessageDTO();
                entityMessageDTO.setIdentityStr(displayName);
                entityMessageDTO.setOid(String.valueOf(cTyEntityBaseDO.getOid()));
                entityMessageDTO.setType(type);
                String message = TyMessageUtil.getMessage(
                        ResponseCodeEnum.BIZ_LIFECYCLESTATE_CHANGE_FAIL_CHECKOUT.getLocaleKey(),
                        new String[]{displayName});
                entityMessageDTO.setMessage(message);
                entityMessageDTOS.add(entityMessageDTO);
            }
        }

    }

    private Map<BigInteger, Map<String, TyLifeCycleStageTemplateDTO>> getTemplateStagesMap(
            List<? extends CTyEntityBaseDO> entityList) {
        List<TyTemplateAndStagesDTO> templateList = this.getTemplateAndStages(entityList);
        Map<BigInteger, Map<String, TyLifeCycleStageTemplateDTO>> templateStatesMap = new HashMap();
        Iterator var4 = templateList.iterator();

        while (true) {
            TyTemplateAndStagesDTO dto;
            do {
                if (!var4.hasNext()) {
                    return templateStatesMap;
                }

                dto = (TyTemplateAndStagesDTO) var4.next();
            } while (TyplmEntityBaseUtil.checkEmptyAndRemoveNull(dto.getStageList()));

            Map<String, TyLifeCycleStageTemplateDTO> stateMap = (Map) templateStatesMap.computeIfAbsent(
                    dto.getTemplateoid(), (k) -> {
                        return new HashMap();
                    });
            Iterator var7 = dto.getStageList().iterator();

            while (var7.hasNext()) {
                TyLifeCycleStageTemplateDTO stageDTO = (TyLifeCycleStageTemplateDTO) var7.next();
                stateMap.put(stageDTO.getStagestate(), stageDTO);
            }
        }
    }

    public List<BigInteger> filterStateList(List<EntityLifeCycleDTO> entityLifeCycleList) {
        List<BigInteger> filterList = new ArrayList();
        entityLifeCycleList.forEach((entityLifeCycleDTO) -> {
            CTyEntityBaseDO entityBaseDO = CommonUtil.getEntity(
                    new IdentifierEntity(entityLifeCycleDTO.getOid(), entityLifeCycleDTO.getOtype()));
            if (entityBaseDO instanceof ITyLifeCycleManaged) {
                String oldLifecycleState = ((ITyLifeCycleManaged) entityBaseDO).getLifecyclestagekey();
                if (!oldLifecycleState.equals(entityLifeCycleDTO.getLifeCycleStageKey())) {
                    filterList.add(entityLifeCycleDTO.getOid());
                }
            }

        });
        return filterList;
    }

    private boolean checkStateNotExist(CTyEntityBaseDO entity,
                                       Map<BigInteger, Map<String, TyLifeCycleStageTemplateDTO>> templateStagesMap,
                                       boolean ignoreNotExistState, String stateCode,
                                       List<EntityMessageDTO> entityMessageDTOS) {
        if (!(entity instanceof ITyLifeCycleManaged)) {
            return true;
        } else {
            String type = (String) FolderQueryConstant.QUERY_OTYPE_TO_TYPE_MAP.getOrDefault(entity.getOtype(),
                                                                                            entity.getOtype());
            String displayName = CommonUtil.getEntityDisplayName(entity);
            EntityMessageDTO entityMessageDTO = new EntityMessageDTO();
            entityMessageDTO.setIdentityStr(displayName);
            entityMessageDTO.setOid(String.valueOf(entity.getOid()));
            entityMessageDTO.setType(type);
            BigInteger lifecycleTemplateOid = ((ITyLifeCycleManaged) entity).getLifecycletemplateoid();
            if (!templateStagesMap.containsKey(lifecycleTemplateOid)) {
                if (ignoreNotExistState) {
                    return true;
                }

                String message = TyMessageUtil.getMessage(
                        ResponseCodeEnum.BIZ_LIFECYCLETEMPLATE_NOT_FOUND.getLocaleKey(), new String[]{displayName});
                entityMessageDTO.setMessage(message);
                entityMessageDTOS.add(entityMessageDTO);
            }

            Map<String, TyLifeCycleStageTemplateDTO> stages = (Map) templateStagesMap.get(lifecycleTemplateOid);
            if (!stages.containsKey(stateCode)) {
                if (ignoreNotExistState) {
                    return true;
                }

                String message = TyMessageUtil.getMessage(
                        ResponseCodeEnum.BIZ_LIFECYCLESTATUS_NOT_IN_OPTIONAL_LIST.getLocaleKey(),
                        new String[]{displayName});
                entityMessageDTO.setMessage(message);
                entityMessageDTOS.add(entityMessageDTO);
            }

            return false;
        }
    }

    private NewLifeCycleStateHistoryDTO newLifecycleHistory(String lastStatus, String status, UserDO userDO,
                                                            CTyEntityBaseDO baseDO) {
        NewLifeCycleStateHistoryDTO newLifeCycleStateHistoryDTO = new NewLifeCycleStateHistoryDTO();
        newLifeCycleStateHistoryDTO.setAction(StatusActionEnum.SETSTATE);
        newLifeCycleStateHistoryDTO.setUserDO(userDO);
        newLifeCycleStateHistoryDTO.setBaseObject(baseDO);
        newLifeCycleStateHistoryDTO.setLifecyclestagekey(lastStatus);
        newLifeCycleStateHistoryDTO.setState(status);
        return newLifeCycleStateHistoryDTO;
    }

    public List<EntityMessageDTO> filterUpdateList(List<EntityMessageDTO> messageDTOList, boolean excludeException,
                                                   List<CTyEntityBaseDO> updateEntityList,
                                                   List<CTyEntityBaseDO> refreshTeamEntityList,
                                                   List<NewLifeCycleStateHistoryDTO> lifeCycleStateHistoryDTOS) {
        TyplmEntityBaseService typlmEntityBaseService = SpringUtil.getBean(TyplmEntityBaseService.class);
        TyplmLifeCycleHistoryService typlmLifeCycleHistoryService = SpringUtil.getBean(
                TyplmLifeCycleHistoryService.class);
        TyplmTeamForStageService typlmTeamForStageService = SpringUtil.getBean(TyplmTeamForStageService.class);
        excludeException = true;
        List<String> entityMessageOids = (List) messageDTOList.stream().map(EntityMessageDTO::getOid).collect(
                Collectors.toList());
        if (!excludeException) {
            if (!CollectionUtils.isEmpty(messageDTOList)) {
                return messageDTOList;
            }

            typlmEntityBaseService.batchUpdateEntityBase(updateEntityList, true);
            if (!CollectionUtils.isEmpty(lifeCycleStateHistoryDTOS)) {
                typlmLifeCycleHistoryService.newLifeCycleStateHistory(lifeCycleStateHistoryDTOS);
            }

            if (ObjectUtils.isNotEmpty(refreshTeamEntityList)) {
                typlmTeamForStageService.batchUpdateTeamByLifeStage(refreshTeamEntityList);
            }
        }
        else {
            List<CTyEntityBaseDO> filterUpdateEntityList = (List) updateEntityList.parallelStream().filter(
                    (updateEntity) -> {
                        return !entityMessageOids.contains(updateEntity.getOid().toString());
                    }).collect(Collectors.toList());
            List<CTyEntityBaseDO> filterRefreshTeamEntityList = (List) refreshTeamEntityList.parallelStream().filter(
                    (refreshTeamEntity) -> {
                        return !entityMessageOids.contains(refreshTeamEntity.getOid().toString());
                    }).collect(Collectors.toList());
            List<NewLifeCycleStateHistoryDTO> filterLifeCycleStateHistorys = (List) lifeCycleStateHistoryDTOS.parallelStream()
                    .filter((lifeCycleStateHistoryDTO) -> {
                        return !entityMessageOids.contains(
                                lifeCycleStateHistoryDTO.getBaseObject().getOid().toString());
                    }).collect(Collectors.toList());
            typlmEntityBaseService.batchUpdateEntityBase(filterUpdateEntityList, true);
            if (!CollectionUtils.isEmpty(filterLifeCycleStateHistorys)) {
                typlmLifeCycleHistoryService.newLifeCycleStateHistory(filterLifeCycleStateHistorys);
            }

            if (ObjectUtils.isNotEmpty(refreshTeamEntityList)) {
                typlmTeamForStageService.batchUpdateTeamByLifeStage(filterRefreshTeamEntityList);
            }
        }

        return new ArrayList();
    }

}
